import time
def read_from_file(filename):
    file = open(filename)
    data = file.readlines()
    data = list(map(int, data))
    return data

m1 = read_from_file('m1_sorted.txt')
print(m1[:10])
m2 = read_from_file('m2_reverse.txt')
print(m2[:10])
m3 = read_from_file('m3_shuffle.txt')
print(m3[:10])


def bubble_sort(a):
    for i in range(len(a) - 1):
        swap = False
        for j in range(len(a) - 1 - i):
            if a[j] > a[j + 1]:
                swap = True
                a[j], a[j + 1] = a[j + 1], a[j]
        if not swap: 
            return
t_start_m1 = time.time()
bubble_sort(m1)
t_finish_m1 = time.time()
time_m1 = round((t_finish_m1 - t_start_m1) * 1000)
print(f'm1_sorted {time_m1} milliseconds')
t_start_m1 = time.time()
bubble_sort(m2)
t_finish_m1 = time.time()
time_m1 = round((t_finish_m1 - t_start_m1) * 1000)
print(f'm2_reverse {time_m1} milliseconds')
t_start_m1 = time.time()
bubble_sort(m3)
t_finish_m1 = time.time()
time_m1 = round((t_finish_m1 - t_start_m1) * 1000)
print(f'm3_shuffle {time_m1} milliseconds')